﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TCP.SocketHelper
{
    /// <summary>
    /// Socket 设置（单例）
    /// </summary>
    public class SocketSetting
    {
        protected static SocketSetting _Instance = null;
        public static SocketSetting Instance
        {
            get
            {
                if(_Instance == null)
                {
                    _Instance = new SocketSetting();
                }

                return _Instance;
            }
        }

        public static void SetInstance(SocketSetting setting)
        {
            _Instance = setting;
        }

        /// <summary>
        /// 消息头长度
        /// </summary>
        public static int SOCKET_MSG_HEAD_LENGTH
        {
            get
            {
                return Instance._SocketMsgHeadLength;
            }
        }

        /// <summary>
        /// 一次性读入消息体的最大缓冲区大小
        /// <para>4096</para>
        /// </summary>
        public static int SOCKET_MSG_BODY_MAX
        {
            get
            {
                return Instance._SocketMsgBodyMax;
            }
        }

        /// <summary>
        /// 消息头校验
        /// <para>默认为0x5055</para>
        /// </summary>
        public static short SOCKET_MSG_HEAD_FLAG
        {
            get
            {
                return Instance._SocketMsgHeadFlag;
            }
        }

        /// <summary>
        /// 超时等待
        /// <para>默认 5 秒</para>
        /// </summary>
        public static int TCP_CONNECT_TIMEOUT
        {
            get
            {
                return Instance._TcpConnectTimeOut;
            }
        }

        /// <summary>
        /// 默认IPv4绑定地址
        /// </summary>
        public static string DEFAULT_IPADDRESS_V4
        {
            get
            {
                return Instance._DefaultIPAddressV4;
            }
        }

        /// <summary>
        /// 自动获取IP的通配符
        /// </summary>
        public static string AUTO_SYMBOL_IP
        {
            get
            {
                return Instance._AutoSymbolIP;
            }
        }

        /// <summary>
        /// 消息校验头
        /// </summary>
        public static byte[] SOCKET_HEAD_FLAG
        {
            get
            {
                return Instance._SocketHeadFlag;
            }
        }

        /// <summary>
        /// 消息头长度
        /// </summary>
        protected int _SocketMsgHeadLength = 8;

        /// <summary>
        /// 一次性读入消息体的最大缓冲区大小
        /// <para>4096</para>
        /// </summary>
        protected int _SocketMsgBodyMax = 4096;

        /// <summary>
        /// 消息头校验
        /// </summary>
        protected short _SocketMsgHeadFlag = 0x5055;

        /// <summary>
        /// 超时等待
        /// <para>默认 5 秒</para>
        /// </summary>
        protected int _TcpConnectTimeOut = 5000;

        /// <summary>
        /// 默认IPv4绑定地址
        /// </summary>
        protected string _DefaultIPAddressV4 = "127.0.0.1";

        /// <summary>
        /// 自动获取IP的通配符
        /// </summary>
        protected string _AutoSymbolIP = "*";

        /// <summary>
        /// 默认的消息校验头
        /// </summary>
        protected byte[] _SocketHeadFlag = new byte[] { 0x55, 0x50 };

    }
}
